import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {Location} from '@angular/common';
import { NormalService } from '../../../apiServices/normal.service';
import { Subscription } from 'rxjs';
import { RequestClientService } from '../../../apiServices/request-client.service';

@Component({
    selector: 'account',
    templateUrl: 'account.template.html',
    styleUrls: ['content.scss']
})

export class AccountComponent implements OnInit {
    public language: string = 'en';
    public firstStage: string;
    public secondStage: string;
    public user: any;
    public leftNav: boolean;

    private userSubscription: Subscription;
    constructor(
        private route: ActivatedRoute,
        private location: Location,
        private normalService: NormalService,
        private requestClientService: RequestClientService,
    ) {
        let pathFromRoot = location.path();
        pathFromRoot = pathFromRoot.substr(1);
        let pathArr = pathFromRoot.split('/');
        [this.firstStage, this.secondStage] = pathArr;
        this.language = normalService.language;
        
        this.userSubscription = this.normalService.request$.subscribe(next => {
            console.log('nextaccount',next);
            if (next.code == 200 && next.name == 'user') {
                this.user = next.data.user;
            }
        });
    }

    toggleLeft(): void {
        this.leftNav = !this.leftNav;
    }

    ngOnInit() :void {

    }
}